package io.gitee.devaper.starlight.security.handler

import io.gitee.devaper.starlight.common.entity.vo.*
import io.gitee.devaper.starlight.common.util.*
import jakarta.servlet.http.*
import org.springframework.context.MessageSource
import org.springframework.context.MessageSourceAware
import org.springframework.security.core.*
import org.springframework.security.web.AuthenticationEntryPoint
import org.springframework.stereotype.Component

/**
 * 认证、鉴权异常处理器
 */
@Component
open class DefaultAuthenticationEntryPoint : AuthenticationEntryPoint, MessageSourceAware {
    override fun commence(
        request: HttpServletRequest,
        response: HttpServletResponse,
        authException: AuthenticationException
    ) {
        response.write(data = ApiResult.unauthenticated(), request = request)
    }

    private lateinit var messageSource: MessageSource

    override fun setMessageSource(messageSource: MessageSource) {
        this.messageSource = messageSource
    }
}